<template>
  <el-card>
    <div style="margin-bottom: 20px; font-size: 20px;color: #606266;">商家小程序 - 订阅管理</div>

    <el-table
      :data="wxappList"
      style="width: 100%"
    >
      <el-table-column
        prop="appName"
        label="小程序名称"
      />

      <el-table-column
        prop="businessName"
        label="商户名称"
      />

      <el-table-column
        prop="categories"
        label="服务目录"
      />

      <el-table-column
        prop="option"
        align="center"
        label="操作"
      >
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="handleViews(scope.row)">订阅消息</el-button>
        </template>
      </el-table-column>

    </el-table>

    <el-pagination
      class="pagination"
      :current-page.sync="pageNum"
      :page-size="pageSize"
      layout="total, prev, pager, next"
      :total="total"
      @current-change="handleCurrentChange"
    />
  </el-card>
</template>

<script>
import { getWxappPage } from '@/api/wxapp'

export default {
  name: 'WxappRelation',

  data() {
    return {
      pageNum: 1,
      pageSize: 10,
      total: 0,
      wxappList: [],
      classifyMap: {},
      tplMap: {}
    }
  },
  mounted() {
    this.getWxappList()
  },
  methods: {

    handleCurrentChange(data) {
      this.pageNum = data
      this.getWxappList()
    },
    handleViews(data) {
      console.info('data:', data)
      this.$router.push({ name: 'wxaTemplateMgr', params: { appId: data.appId } })
    },
    getWxappList() {
      return getWxappPage({
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        state: 1
      }).then((resp) => {
        this.wxappList = resp.data.row
        this.total = resp.data.total
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
  .pagination {
    margin-top: 10px;
  }
  .el-button--text{
	  color: $btnBgc;
  }
  .el-button--text:hover{
	  color: $btnBgc;
	  background-color: #f5f7fa;
	  border-color: #f5f7fa;
  }
</style>
